home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1995 May / PC Answers CD-ROM 7 (Future Publishing) (May 1995).iso / vbits / code / mee / vbdao / visdata / dataform.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-10-06  |  21.3 KB  |  746 lines

  1. VERSION 2.00
  2. Begin Form fDataForm 
  3.    BackColor       =   &H00C0C0C0&
  4.    ClientHeight    =   2520
  5.    ClientLeft      =   1815
  6.    ClientTop       =   3000
  7.    ClientWidth     =   5700
  8.    Height          =   2925
  9.    Icon            =   0
  10.    Left            =   1755
  11.    LinkTopic       =   "Form2"
  12.    MDIChild        =   -1  'True
  13.    ScaleHeight     =   2520
  14.    ScaleWidth      =   5700
  15.    Tag             =   "Dynaset"
  16.    Top             =   2655
  17.    Width           =   5820
  18.    Begin CommonDialog CMD1 
  19.       Left            =   4800
  20.       Top             =   1800
  21.    End
  22.    Begin PictureBox StatBox 
  23.       Align           =   2  'Align Bottom
  24.       BackColor       =   &H00C0C0C0&
  25.       BorderStyle     =   0  'None
  26.       Height          =   270
  27.       Left            =   0
  28.       ScaleHeight     =   282.462
  29.       ScaleMode       =   0  'User
  30.       ScaleWidth      =   5710.27
  31.       TabIndex        =   6
  32.       Top             =   2250
  33.       Width           =   5700
  34.       Begin Data Data1 
  35.          Connect         =   ""
  36.          DatabaseName    =   ""
  37.          Exclusive       =   0   'False
  38.          Height          =   270
  39.          Left            =   0
  40.          Options         =   0
  41.          ReadOnly        =   0   'False
  42.          RecordSource    =   ""
  43.          Top             =   0
  44.          Width           =   5475
  45.       End
  46.    End
  47.    Begin VScrollBar cScrollBar 
  48.       Height          =   2085
  49.       LargeChange     =   3000
  50.       Left            =   7665
  51.       SmallChange     =   300
  52.       TabIndex        =   15
  53.       Top             =   630
  54.       Visible         =   0   'False
  55.       Width           =   255
  56.    End
  57.    Begin PictureBox cFields 
  58.       BackColor       =   &H00C0C0C0&
  59.       BorderStyle     =   0  'None
  60.       Height          =   1065
  61.       Left            =   0
  62.       ScaleHeight     =   1056.479
  63.       ScaleMode       =   0  'User
  64.       ScaleWidth      =   7600.262
  65.       TabIndex        =   10
  66.       TabStop         =   0   'False
  67.       Top             =   630
  68.       Width           =   7605
  69.       Begin TextBox cFieldData 
  70.          BackColor       =   &H00FFFFFF&
  71.          DataSource      =   "Data1"
  72.          ForeColor       =   &H00000000&
  73.          Height          =   285
  74.          Index           =   0
  75.          Left            =   1665
  76.          TabIndex        =   13
  77.          Top             =   0
  78.          Visible         =   0   'False
  79.          Width           =   3255
  80.       End
  81.       Begin CheckBox cFieldCheck 
  82.          BackColor       =   &H00C0C0C0&
  83.          DataSource      =   "Data1"
  84.          Height          =   282
  85.          Index           =   0
  86.          Left            =   1680
  87.          TabIndex        =   12
  88.          Top             =   735
  89.          Visible         =   0   'False
  90.          Width           =   3270
  91.       End
  92.       Begin PictureBox cFieldPicture 
  93.          DataSource      =   "Data1"
  94.          Height          =   282
  95.          Index           =   0
  96.          Left            =   1680
  97.          ScaleHeight     =   255
  98.          ScaleWidth      =   3240
  99.          TabIndex        =   11
  100.          Top             =   315
  101.          Visible         =   0   'False
  102.          Width           =   3270
  103.       End
  104.       Begin Label cFieldName 
  105.          BackColor       =   &H00C0C0C0&
  106.          ForeColor       =   &H00000000&
  107.          Height          =   255
  108.          Index           =   0
  109.          Left            =   105
  110.          TabIndex        =   14
  111.          Top             =   0
  112.          Visible         =   0   'False
  113.          Width           =   1575
  114.       End
  115.    End
  116.    Begin PictureBox FieldHeader 
  117.       Align           =   1  'Align Top
  118.       BackColor       =   &H00C0C0C0&
  119.       BorderStyle     =   0  'None
  120.       Height          =   300
  121.       Left            =   0
  122.       ScaleHeight     =   300
  123.       ScaleMode       =   0  'User
  124.       ScaleWidth      =   5703.402
  125.       TabIndex        =   7
  126.       Top             =   330
  127.       Width           =   5700
  128.       Begin Label FieldValueLabel 
  129.          BackColor       =   &H00C0C0C0&
  130.          Caption         =   " Value:"
  131.          Height          =   252
  132.          Left            =   1680
  133.          TabIndex        =   9
  134.          Top             =   30
  135.          Width           =   2652
  136.       End
  137.       Begin Label FieldHdrLabel 
  138.          BackColor       =   &H00C0C0C0&
  139.          Caption         =   "Field Name:"
  140.          Height          =   252
  141.          Left            =   120
  142.          TabIndex        =   8
  143.          Top             =   30
  144.          Width           =   1212
  145.       End
  146.    End
  147.    Begin PictureBox TopPic 
  148.       Align           =   1  'Align Top
  149.       BackColor       =   &H00C0C0C0&
  150.       BorderStyle     =   0  'None
  151.       Height          =   330
  152.       Left            =   0
  153.       ScaleHeight     =   330
  154.       ScaleWidth      =   5700
  155.       TabIndex        =   0
  156.       Top             =   0
  157.       Width           =   5700
  158.       Begin CommandButton CancelAddBtn 
  159.          Caption         =   "C&ancel"
  160.          Height          =   330
  161.          Left            =   0
  162.          TabIndex        =   17
  163.          Top             =   0
  164.          Visible         =   0   'False
  165.          Width           =   960
  166.       End
  167.       Begin CommandButton RefreshBtn 
  168.          Caption         =   "&Refresh"
  169.          Height          =   330
  170.          Left            =   3780
  171.          TabIndex        =   16
  172.          Top             =   0
  173.          Width           =   960
  174.       End
  175.       Begin CommandButton FindBtn 
  176.          Caption         =   "&Find"
  177.          Height          =   330
  178.          Left            =   2835
  179.          TabIndex        =   5
  180.          Top             =   0
  181.          Width           =   960
  182.       End
  183.       Begin CommandButton CloseBtn 
  184.          Cancel          =   -1  'True
  185.          Caption         =   "&Close"
  186.          Height          =   330
  187.          Left            =   4725
  188.          TabIndex        =   4
  189.          Top             =   0
  190.          Width           =   960
  191.       End
  192.       Begin CommandButton DeleteBtn 
  193.          Caption         =   "&Delete"
  194.          Height          =   330
  195.          Left            =   1890
  196.          TabIndex        =   3
  197.          Top             =   0
  198.          Width           =   960
  199.       End
  200.       Begin CommandButton AddBtn 
  201.          Caption         =   "&Add"
  202.          Height          =   330
  203.          Left            =   0
  204.          TabIndex        =   2
  205.          Top             =   0
  206.          Width           =   960
  207.       End
  208.       Begin CommandButton UpdateBtn 
  209.          Caption         =   "&Update"
  210.          Height          =   330
  211.          Left            =   945
  212.          TabIndex        =   1
  213.          Top             =   0
  214.          Width           =   960
  215.       End
  216.    End
  217. '============================================================================
  218. ' This is a fairly generic form that can be used in most cases with any
  219. ' table. I am sorry if it is confusing. There is a lot of paths to
  220. ' keep track on with adding, editing, browsing, deleting records
  221. ' on populated as well as empty tables. I have added flags where I
  222. ' felt there was no other way to achieve the correct functionality.
  223. ' I am sure that you can improve this form greatly with a little
  224. ' time and understanding of your spcific needs. There is also some
  225. ' recursion that could be trapped but hopefully, the form will be
  226. ' a good starting point for any data control app.
  227. '============================================================================
  228. Dim FldArr() As Control
  229. Dim FDS As dynaset
  230. Dim FBM As String                  'form global bookmark
  231. Dim numFlds As Integer
  232. Dim CurrField As Integer
  233. Dim CurrRec As Long
  234. Dim TotRec As Long
  235. Dim JustUsedFind As Integer        'flag for find function
  236. Dim fResizing As Integer           'flag to avoid resize recursion
  237. Dim CancelFlag As Integer          'flag to cancel an addnew
  238. Dim FldTop As Integer
  239. Const EM_NOTHING = 0
  240. Const EM_EDIT = 1
  241. Const EM_ADDNEW = 2
  242. Const FT_TRUEFALSE = 1
  243. Const FT_BYTE = 2
  244. Const FT_INTEGER = 3
  245. Const FT_LONG = 4
  246. Const FT_CURRENCY = 5
  247. Const FT_SINGLE = 6
  248. Const FT_DOUBLE = 7
  249. Const FT_DATETIME = 8
  250. Const FT_STRING = 10
  251. Const FT_BINARY = 11
  252. Const FT_MEMO = 12
  253. Const YES = 6
  254. Const MSGBOX_TYPE = 4 + 48
  255. Sub AddBtn_Click ()
  256.   On Error GoTo AddErr
  257.   Data1.Recordset.AddNew
  258.   Data1.Caption = "New Record"
  259.   CancelAddBtn.Visible = True
  260.   AddBtn.Visible = False
  261.   If Data1.Recordset.RecordCount <> 0 Then
  262.     FBM = Data1.Recordset.Bookmark
  263.     FldArr(0).SetFocus
  264.   End If
  265.   GoTo AddEnd
  266. AddErr:
  267.   MsgBox Error$
  268.   Resume AddEnd
  269. AddEnd:
  270. End Sub
  271. Sub CancelAddBtn_Click ()
  272.   On Error Resume Next
  273.   CancelFlag = True
  274.   If Len(FBM) > 0 Then
  275.     Data1.Recordset.Bookmark = FBM
  276.   End If
  277.   If FDS.RecordCount > 0 Then
  278.     SetRecNum
  279.   End If
  280. End Sub
  281. Sub cFieldData_KeyPress (Index As Integer, KeyAscii As Integer)
  282.   'go to next field on an enter keypress
  283.   If KeyAscii = 13 Then
  284.     KeyAscii = 0
  285.     SendKeys "{Tab}"
  286.   End If
  287. End Sub
  288. Sub cFieldPicture_Click (Index As Integer)
  289.   'this toggles the size of a picture control
  290.   'so it mat be viewed or compressed
  291.   If cFieldPicture(Index).Height <= 280 Then
  292.     cFieldPicture(Index).AutoSize = True
  293.   Else
  294.     cFieldPicture(Index).AutoSize = False
  295.     cFieldPicture(Index).Height = 280
  296.   End If
  297. End Sub
  298. Sub cFieldPicture_DblClick (Index As Integer)
  299.   On Error GoTo PicErr
  300.   CMD1.Filter = "Bitmaps (*.bmp)|*.bmp|Icons (*.ico)|*.ico|Metafiles (*.wmf)|*.wmf|All Files (*.*)|*.*"
  301.   CMD1.DialogTitle = "Select a Picture File to Load"
  302.   CMD1.FilterIndex = 1
  303.   CMD1.Action = 1
  304.   If Len(CMD1.Filename) > 0 Then
  305.     cFieldPicture(Index).Picture = LoadPicture(CMD1.Filename)
  306.   End If
  307.   GoTo PicEnd
  308. PicErr:
  309.   MsgBox Error$
  310.   Resume PicEnd
  311. PicEnd:
  312. End Sub
  313. Sub CloseBtn_Click ()
  314.   On Error Resume Next
  315.   Unload Me
  316. End Sub
  317. Sub cScrollBar_Change ()
  318.   Dim t As Integer
  319.   t = cScrollBar
  320.   If (t - FldTop) Mod 300 = 0 Then
  321.     cFields.Top = t
  322.   Else
  323.     cFields.Top = ((t - FldTop) \ 300) * 300 + FldTop
  324.   End If
  325. End Sub
  326. Sub Data1_Error (DataErr As Integer, Response As Integer)
  327.   If DataErr = 481 Then  'throw away bad picture error
  328.     Response = 0
  329.   Else
  330.     MsgBox "Data error event hit err:" & Error$(DataErr)
  331.   End If
  332. End Sub
  333. Sub Data1_RePosition ()
  334.   Dim bm As String
  335.   Dim ds As dynaset
  336.   If Data1.Recordset.RecordCount = 0 And Data1.EditMode <> 2 Then
  337.     Call AddBtn_Click
  338.     Exit Sub
  339.   End If
  340.   If JustUsedFind = True Then
  341.     Set ds = Data1.Recordset.Clone()
  342.     bm = Data1.Recordset.Bookmark
  343.     ds.MoveFirst
  344.     CurrRec = 1
  345.     While ds.Bookmark <> bm
  346.       CurrRec = CurrRec + 1
  347.       ds.MoveNext
  348.     Wend
  349.     JustUsedFind = False
  350.   End If
  351.   SetRecNum
  352. End Sub
  353. Sub Data1_Validate (Action As Integer, Save As Integer)
  354.   On Error GoTo ValErr
  355.   If CancelFlag Then
  356.     Save = False
  357.     CancelFlag = False
  358.     Exit Sub
  359.   End If
  360.   'first check for a move from an addnew or edit record
  361.   If Action < 5 Then
  362.     If Save = True Then      'data changed
  363.       If Data1.EditMode = EM_ADDNEW Then
  364.         If MsgBox("Save New Record?", MSGBOX_TYPE) = YES Then
  365.           TotRec = TotRec + 1
  366.         Else
  367.           Save = False
  368.         End If
  369.       Else
  370.         If MsgBox("Commit Changes?", MSGBOX_TYPE) <> YES Then
  371.           Save = False        'loose changes
  372.         End If
  373.       End If
  374.     End If
  375.     SetRecNum
  376.   End If
  377.   Select Case Action
  378.     Case 1          'First
  379.       CurrRec = 1
  380.     Case 2          'Previous
  381.       If CurrRec = 1 Then Beep
  382.       If CurrRec <> 1 Then CurrRec = CurrRec - 1
  383.     Case 3          'Next
  384.       If CurrRec = TotRec Then Beep
  385.       If CurrRec <> TotRec Then CurrRec = CurrRec + 1
  386.     Case 4          'Last
  387.       CurrRec = TotRec
  388.     Case 5          'AddNew
  389.       'do nothing
  390.     Case 6          'Update
  391.        'moved to the updatebtn_click event code
  392.     Case 7          'Delete
  393.       TotRec = TotRec - 1
  394.       SetRecNum
  395.     Case 8
  396.       'set the flag for use in the reposition event
  397.       JustUsedFind = True
  398.     Case 9          'BookMark
  399.       'do nothing"
  400.     Case 10          'Close
  401.       If Save = True Then
  402.         If MsgBox("Commit Changes before Closing?", MSGBOX_TYPE) <> YES Then
  403.           Save = False
  404.         End If
  405.       End If
  406.   End Select
  407.   GoTo ValEnd
  408. ValErr:
  409.   ShowError
  410.   Resume ValEnd
  411. ValEnd:
  412. End Sub
  413. Sub DeleteBtn_Click ()
  414.   On Error GoTo DELErr
  415.   If MsgBox("Delete Current Record?", MSGBOX_TYPE) = YES Then
  416.     Data1.Recordset.Delete
  417.     Data1.Recordset.MoveNext
  418.     FldArr(0).SetFocus
  419.   End If
  420.   GoTo DelEnd
  421. DELErr:
  422.   MsgBox Error$
  423.   Resume DelEnd
  424. DelEnd:
  425. End Sub
  426. Sub FindBtn_Click ()
  427.   On Error GoTo FindErr
  428.   Dim bm As String, findstr As String
  429.   findstr = InputBox("Enter Search Expression:")
  430.   If Len(findstr) = 0 Then Exit Sub
  431.   If Data1.Recordset.RecordCount > 0 Then
  432.     bm = Data1.Recordset.Bookmark
  433.   End If
  434.   Data1.Recordset.FindFirst findstr
  435.   'return to old record if no match was found
  436.   If Data1.Recordset.NoMatch And Len(bm) > 0 Then
  437.     Data1.Recordset.Bookmark = bm
  438.   End If
  439.   GoTo FindEnd
  440. FindErr:
  441.   MsgBox Error$
  442.   Resume FindEnd
  443. FindEnd:
  444.   FldArr(0).SetFocus
  445. End Sub
  446. Sub Form_Load ()
  447.   Dim ds2 As dynaset
  448.   Dim Start, Finish
  449.   On Error GoTo LoadErr
  450.   '-------------------------------------------------------
  451.   'this is where the data control properties get
  452.   'set from whatever source they are coming from
  453.   'in this case, it is form1 controls
  454.   '-------------------------------------------------------
  455.   If gstDataType <> SQLDB Then
  456.     Data1.DatabaseName = gCurrentDB.Name
  457.   End If
  458.   Data1.Connect = gCurrentDB.Connect
  459.   'determine if a table name or sql statement is used
  460.   If gfFromSQL = True Then
  461.     If Len(gstDynaString) = 0 Then
  462.       Data1.RecordSource = fSQL.cSQLStatement
  463.     Else
  464.       Data1.RecordSource = gstDynaString
  465.     End If
  466.     Caption = "Dynaset: SQL Statement"
  467.   Else
  468.     If VDMDI.cPassThru.Visible = True And VDMDI.cPassThru = 1 Then
  469.       Data1.RecordSource = "select * from " & StripOwner((fTables.cTableList))
  470.     Else
  471.       Data1.RecordSource = fTables.cTableList
  472.     End If
  473.     Caption = "Dynaset: " & UCase(fTables.cTableList)
  474.   End If
  475.   '-------------------------------------------------------
  476.   If VDMDI.cPassThru.Visible = True And VDMDI.cPassThru = 1 Then
  477.     Data1.Options = VBDA_SQLPASSTHROUGH
  478.   End If
  479.   Start = TimeGetTime()
  480.   Data1.Refresh
  481.   CurrRec = 1
  482.   Set ds2 = Data1.Recordset.Clone()
  483.   If ds2.BOF = False Then
  484.     ds2.MoveLast
  485.     TotRec = ds2.RecordCount
  486.   Else
  487.     TotRec = 0
  488.   End If
  489.   ds2.Close
  490.   Width = 5805
  491.   LoadFields
  492.   Me.Show
  493.   FldArr(0).SetFocus
  494.   SetRecNum
  495.   Finish = TimeGetTime()
  496.   If VDMDI.PrefShowPerf.Checked Then
  497.     MsgBox TotRec & " rows found in " & (Finish - Start) / 1000 & " seconds!", 48
  498.   End If
  499.   GoTo LoadEnd
  500. LoadErr:
  501.   If Err = 3061 Then
  502.     Beep
  503.     MsgBox "Parameterized Queries not available with Data Control!"
  504.   Else
  505.     ShowError
  506.   End If
  507.   Unload Me
  508.   Resume LoadEnd
  509. LoadEnd:
  510. End Sub
  511. Sub Form_Resize ()
  512.   On Error Resume Next
  513.   If fResizing = True Then Exit Sub
  514.   Dim h As Integer, i As Integer
  515.   Dim totw As Integer
  516.   fResizing = True
  517.   If WindowState <> 1 And cFieldName(0).Visible = True Then 'not minimized
  518.     'make sure the form is lined up on a field
  519.     h = Height
  520.     If (h - 1320) Mod 300 <> 0 Then
  521.       Height = ((h - 1320) \ 300) * 300 + 1320
  522.     End If
  523.     'resize the status bar
  524.     StatBox.Top = Height - 650
  525.     'resize the scrollbar
  526.     cScrollBar.Height = StatBox.Top - (FieldHeader.Top - FieldHeader.Height) - 600
  527.     cScrollBar.Left = Width - 360
  528.     If FDS.Fields.Count > 10 Then
  529.       cFields.Width = Width - 260
  530.       totw = cScrollBar.Left - 20
  531.     Else
  532.       cFields.Width = Width - 20
  533.       totw = Width - 50
  534.     End If
  535.     FieldHeader.Width = Width - 20
  536.     'widen the fields if possible
  537.     For i = 0 To FDS.Fields.Count - 1
  538.       cFieldName(i).Width = .3 * totw
  539.       FldArr(i).Left = cFieldName(i).Width + 20
  540.       If Data1.Recordset.Fields(i).Type > 9 Then
  541.         FldArr(i).Width = .7 * totw - 270
  542.       End If
  543.     Next
  544.     FieldValueLabel.Left = FldArr(0).Left
  545.   End If
  546.   Data1.Width = StatBox.Width
  547.   fResizing = False
  548. End Sub
  549. Function GetFieldWidth (t As Integer)
  550.   'determines the form control width
  551.   'based on the field type
  552.   Select Case t
  553.     Case FT_TRUEFALSE
  554.       GetFieldWidth = 850
  555.     Case FT_BYTE
  556.       GetFieldWidth = 650
  557.     Case FT_INTEGER
  558.       GetFieldWidth = 900
  559.     Case FT_LONG
  560.       GetFieldWidth = 1100
  561.     Case FT_CURRENCY
  562.       GetFieldWidth = 1800
  563.     Case FT_SINGLE
  564.       GetFieldWidth = 1800
  565.     Case FT_DOUBLE
  566.       GetFieldWidth = 2200
  567.     Case FT_DATETIME
  568.       GetFieldWidth = 2000
  569.     Case FT_STRING
  570.       GetFieldWidth = 3250
  571.     Case FT_MEMO
  572.       GetFieldWidth = 3250
  573.     Case Else
  574.       GetFieldWidth = 3250
  575.   End Select
  576. End Function
  577. Sub LoadFields ()
  578.    Dim t As dynaset
  579.    Dim ds As String        'temp dynaset name string
  580.    Dim ft As Integer
  581.    Dim i As Integer
  582.    On Error GoTo LoadFieldsErr
  583.    Set FDS = Data1.Recordset
  584.    Set t = FDS
  585.    'load the controls on the dynaset form
  586.    numFlds = t.Fields.Count
  587.    ReDim FldArr(numFlds) As Control
  588.    cFieldName(0).Visible = True
  589.    ft = t.Fields(0).Type
  590.    If ft = FT_TRUEFALSE Then
  591.      Set FldArr(0) = cFieldCheck(0)
  592.    ElseIf ft = FT_BINARY Then
  593.      Set FldArr(0) = cFieldPicture(0)
  594.    Else
  595.      Set FldArr(0) = cFieldData(0)
  596.    End If
  597.    FldArr(0).Visible = True
  598.    FldArr(0).Top = 0
  599.    FldArr(0).Width = GetFieldWidth(ft)
  600.    If ft = FT_STRING Then FldArr(0).MaxLength = t.Fields(0).Size
  601.    FldArr(0).TabIndex = 0
  602.    On Error Resume Next
  603.    For i = 1 To t.Fields.Count - 1
  604.      cFields.Height = cFields.Height + 300
  605.      Load cFieldName(i)
  606.      cFieldName(i).Top = cFieldName(i - 1).Top + 300
  607.      cFieldName(i).Visible = True
  608.      ft = t.Fields(i).Type
  609.      If ft = FT_TRUEFALSE Then
  610.        Load cFieldCheck(i)
  611.        Set FldArr(i) = cFieldCheck(i)
  612.      ElseIf ft = FT_BINARY Then
  613.        Load cFieldPicture(i)
  614.        Set FldArr(i) = cFieldPicture(i)
  615.      Else
  616.        Load cFieldData(i)
  617.        Set FldArr(i) = cFieldData(i)
  618.      End If
  619.      FldArr(i).Top = FldArr(i - 1).Top + 300
  620.      FldArr(i).Visible = True
  621.      FldArr(i).Width = GetFieldWidth(ft)
  622.      FldArr(i).TabIndex = i
  623.      If ft = FT_STRING Then FldArr(i).MaxLength = t.Fields(i).Size
  624.    Next
  625.    On Error GoTo LoadFieldsErr
  626.    'resize main window
  627.    cFields.Top = FieldHeader.Top + FieldHeader.Height
  628.    FldTop = cFields.Top
  629.    cScrollBar = FldTop
  630.    If i <= 10 Then
  631.      Height = i * 300 + 1500
  632.      cScrollBar.Visible = False
  633.    Else
  634.      Height = 4500
  635.      Width = Width + 260
  636.      cScrollBar.Visible = True
  637.      cScrollBar.Min = FldTop
  638.      cScrollBar.Max = FldTop - (i * 300) + 3000
  639.    End If
  640.    'display the field names
  641.    For i = 0 To t.Fields.Count - 1
  642.      cFieldName(i) = UCase(t.Fields(i).Name) & ":"
  643.    Next
  644.    'bind the controls
  645.    On Error Resume Next   'bind even if table is empty
  646.    For i = 0 To t.Fields.Count - 1
  647.      FldArr(i).DataField = t.Fields(i).Name
  648.    Next
  649.    GoTo LoadFieldsEnd
  650. LoadFieldsErr:
  651.    MsgBox Error$
  652.    Resume LoadFieldsEnd
  653. LoadFieldsEnd:
  654. End Sub
  655. Sub MoveBtn_Click (Index As Integer)
  656.   On Error GoTo moveerr
  657.   Dim bm As String
  658.   If Not Data1.Recordset.BOF And Not Data1.Recordset.EOF Then
  659.     bm = Data1.Recordset.Bookmark
  660.   End If
  661.   Select Case Index
  662.     Case 0
  663.       If Len(findval) > 0 Then
  664.         Data1.Recordset.FindFirst findval
  665.       Else
  666.         Data1.Recordset.MoveFirst
  667.       End If
  668.     Case 1
  669.       If Len(findval) > 0 Then
  670.         Data1.Recordset.FindPrevious findval
  671.       Else
  672.         Data1.Recordset.MovePrevious
  673.       End If
  674.     Case 2
  675.       If Len(findval) > 0 Then
  676.         Data1.Recordset.FindNext findval
  677.       Else
  678.         Data1.Recordset.MoveNext
  679.       End If
  680.     Case 3
  681.       If Len(findval) > 0 Then
  682.         Data1.Recordset.FindLast findval
  683.       Else
  684.         Data1.Recordset.MoveLast
  685.       End If
  686.   End Select
  687.   'return to old record if no match was found
  688.   If Data1.Recordset.NoMatch And Len(bm) > 0 Then
  689.     Data1.Recordset.Bookmark = bm
  690.   End If
  691.   GoTo moveend
  692. moveerr:
  693.   MsgBox Error$
  694.   Resume moveend
  695. moveend:
  696.   FldArr(0).SetFocus
  697. End Sub
  698. Sub RefreshBtn_Click ()
  699.   On Error GoTo RefErr
  700.   Data1.Refresh
  701.   GoTo RefEnd
  702. RefErr:
  703.   ShowError
  704.   Resume RefEnd
  705. RefEnd:
  706. End Sub
  707. Sub SetRecNum ()
  708.   If Data1.EditMode <> 2 Then
  709.     If Data1.Recordset.BOF = True Then
  710.       Data1.Caption = "Record BOF of " & TotRec
  711.     ElseIf Data1.Recordset.EOF = True Then
  712.       Data1.Caption = "Record EOF of " & TotRec
  713.     Else
  714.       Data1.Caption = "Record " & CurrRec & " of " & TotRec
  715.     End If
  716.   End If
  717.   'reset buttons if needed
  718.   If Data1.EditMode <> 2 Then
  719.     CancelAddBtn.Visible = False
  720.     AddBtn.Visible = True
  721.   End If
  722. End Sub
  723. Sub UpdateBtn_Click ()
  724.   On Error GoTo UpdErr
  725.   Dim addflag As Integer
  726.   addflag = Data1.EditMode
  727.   If Data1.EditMode = EM_ADDNEW Then
  728.     If MsgBox("Save New Record?", MSGBOX_TYPE) = YES Then
  729.       Data1.Recordset.Update
  730.       TotRec = TotRec + 1
  731.     End If
  732.   Else
  733.     If MsgBox("Commit Changes?", MSGBOX_TYPE) = YES Then
  734.       Data1.Recordset.Update
  735.     End If
  736.   End If
  737.   If addflag = 2 Then
  738.     FDS.MoveLast
  739.   End If
  740.   GoTo UpdEnd
  741. UpdErr:
  742.   ShowError
  743.   Resume UpdEnd
  744. UpdEnd:
  745. End Sub
  746.